home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS12.ADF
/
Star10
/
star10.asm
< prev
next >
Wrap
Assembly Source File
|
1986-08-05
|
17KB
|
629 lines
*
* File: stars.asm August 11, 1986
*
* Version: 1.0
*
* By: Andrew Tuline CIS: 70465,1223
* Vancouver, B.C.
*
* This program does the following:
*
* opens intuition library
* opens a screen
* opens a window in workbench screen
* top:
* draws starfield on screen
* checks for close window message
* if not pressed goto top
* closes a window in workbench screen
* closes a screen
* closes intuition library
* exits to CLI
*
* Assemble and link instructions as follows:
*
* 1) Put stars.asm and stin.asm into the root directory of your assembly
* language disk which is in drive df1: and execute the following:
*
* cd df1:include
* :c/assem :stin.asm -o ram:stin.o -c w120000
* :c/assem :stars.asm -o ram:stars.o
* copy :lib/amiga.lib ram:
* cd ram:
* df1:c/alink from stars.o+stin.o to stars library amiga.lib
*
*
* The reason for putting includes in a separate file and then included at
* link time is to decrease assembly time for the main program during
* development.
*
* old colours new colours
* =========== ===========
* 0 = blue 0 = black (background)
* 1 = white 1 = white
* 2 = black 2 = blue
* 3 = yellow 3 = yellow
* 4-7 = unused 4-7 = unused
*
* Note: I originally wrote this program for the IBM PC.
* The Amiga version in comparison is not that fast.
* Other features to follow are:
*
* speed variations
* turning
* doppler effect
* brightness vs. distance
*
* Two interesting notes not required by this program for programmers:
*
* FUNC_CNT should be -30 in include/exec/funcdef.i (DOS 1.1)
* CLI parameters are passed as: A0 has pointer, D0 has length
*
***************************************************************************
* Macros
EXT_SYS MACRO
XREF _LVO\1
ENDM
SYS MACRO
JSR _LVO\1
ENDM
* System calls (some aren't currently used) (they are defined in amiga.lib)
* exec calls
EXT_SYS OpenLibrary * (libName,version)(A1,D0)
EXT_SYS CloseLibrary * (libbNode)(A1)
EXT_SYS GetMsg * (msgPort)(D0)
EXT_SYS ReplyMsg * (message)(A1)
EXT_SYS Wait * (signalSet)(D0)
* intuition calls
EXT_SYS OpenWindow * (newWindow)(A0)
EXT_SYS CloseWindow * (Window)(A0)
EXT_SYS OpenScreen * (newScreen)(A0)
EXT_SYS CloseScreen * (Screen)(A0)
EXT_SYS ShowTitle * (Screen,ShowIt)(A0,D0)
* graphics calls
EXT_SYS Draw * (rp,x,y)(A1,D0,D1)
EXT_SYS Move * (rp,x,y)(A1,D0,D1)
EXT_SYS ReadPixel * (rp,x,y)(A1,D0,D1)
EXT_SYS SetAPen * (rp,pennum)(A1,D0:8)
EXT_SYS SetDrMd * (rp,drawmode)(A1,D0)
EXT_SYS SetRGB4 * (vp,n,r,g,b)(a0,d0,d1:4,d2:4,d3:4)
EXT_SYS WritePixel * (rp,x,y)(A1,D0,D1)
EXT_SYS SetRast * (rp,pennum)(A1,D0)
* externally defined variables
XREF _AbsExecBase * see amiga.lib
XREF ns_DefaultTitle * see include files
XREF sc_RastPort
XREF sc_ViewPort
XREF nw_Title
XREF RP_JAM1
XREF wd_UserPort
XREF im_Class * IDCMP class long word
XREF MP_SIGBIT
XREF CLOSEWINDOW
XREF CUSTOMSCREEN * not currently used
XREF WBENCHSCREEN
XREF ANDREWSGADGETS * see stin.asm
XREF IDCMP_FLAGS
**************************************************************************
* Start of Code *
**************************************************************************
startup:
move.l sp,savesp
jsr openlibraries
jsr openmystuff
jsr setcolours
jsr starinstall
redostars:
jsr starun
jsr getmsg * d0 has pointer to message
tst.l d0
beq redostars * jump back if no message pointer
move.l d0,a0
move.l im_Class(a0),d0
andi.l #CLOSEWINDOW,d0
beq redostars * jump back if not CLOSEWINDOW msg
* jsr replymsg * should be right after getmsg
stopprog:
jsr closeall
exitprog:
move.l savesp,sp
rts
*****************************************************
* Open Intuition Library
openlibraries:
move.l _AbsExecBase,a6
lea.l theintuition,a1
moveq #0,d0
SYS OpenLibrary(a6)
move.l d0,intuitionbase * d0 is passed back
beq openerr
* Open Graphics Library
move.l _AbsExecBase,a6
lea.l thegraphics,a1
moveq #0,d0
SYS OpenLibrary(a6)
move.l d0,graphicsbase
beq openerr
rts
**************************************************************
* Open a screen
openmystuff:
move.l intuitionbase,a6
lea screenvars,a0
SYS OpenScreen(a6)
move.l d0,newscreenptr * d0 has address of screen
beq openerr
add.l #sc_RastPort,d0 * get the rastport value
move.l d0,myraster
sub.l #sc_RastPort,d0
add.l #sc_ViewPort,d0 * get the viewport value
move.l d0,myview
move.l intuitionbase,a6 * hide the screentitle
move.l newscreenptr,a0
move.l #0,d0
SYS ShowTitle(a6)
* Open a window
move.l intuitionbase,a6
lea windowvars,a0
SYS OpenWindow(a6)
move.l d0,newwindowptr
beq openerr
rts
*************************************************************
setcolours:
* Set the background to black and the other to blue (flip 0 and 2)
setblackback:
move.l graphicsbase,a6
move.l myview,a0
move.l #0,d0 * set colour 0 to:
move.b #0,d1 * red +
move.b #0,d2 * green +----> black
move.b #0,d3 * blue +
SYS SetRGB4(a6)
move.l graphicsbase,a6
move.l myview,a0
move.l #2,d0 * set colour 2 to:
move.b #0,d1 * red +
move.b #0,d2 * green +----> blue
move.b #10,d3 * blue +
SYS SetRGB4(a6)
* Set the drawing mode
move.l graphicsbase,a6
move.l myraster,a1
move.b RP_JAM1,d0
SYS SetDrMd(a6)
rts
*************************************************************
starinstall:
lea pont,a3
lea pontend,a4
newstars:
jsr point_maker
add.w #lenth,a3
cmpa.l a4,a3
blt newstars
move.b #1,speed * initialize various parmeters
move.w #160*64,x_centre
move.w #99*64,y_centre
move.w #0,x_abs
move.w #0,y_abs
rts
*************************************************************
starun:
lea pont,a3
lea pontend,a4
starup:
move.b speed,d4
move.w xold_st(a3),d2
move.w d2,d5
sub.w x_centre,d5
asr.w d4,d5 * shift delx by speed factor
move.b dx_st(a3),d4
asr.w d4,d5 * distance across factor
add.w d5,d2
sub.w x_abs,d2
sub.w x_abs,d2
cmp.w #x_rang,d2
bcc str_out_rang
cmp.w #xlower,d2
bls str_out_rang
move.w d2,xnew_st(a3)
move.b speed,d4
move.w yold_st(a3),d2 * d2 <- yold
move.w d2,d5
sub.w y_centre,d5
asr.w d4,d5
move.b dx_st(a3),d4
asr.w d4,d5
add.w d5,d2
sub.w y_abs,d2
sub.w y_abs,d2
cmp.w #y_rang,d2
bcc str_out_rang
cmp.w #ylower,d2
bls str_out_rang
move.w d2,ynew_st(a3)
move.w xold_st(a3),d0 * preset old point
move.w yold_st(a3),d1
bsr preset
move.w xnew_st(a3),d0 * pset new point
move.w ynew_st(a3),d1
bsr pset
move.w xnew_st(a3),xold_st(a3)
move.w ynew_st(a3),yold_st(a3)
bra next_star
str_out_rang:
move.w xold_st(a3),d0
move.w yold_st(a3),d1
bsr preset
bsr point_maker
next_star:
add.w #lenth,a3
cmpa.l a4,a3
blt starup
starend:
rts
*************************************************************
preset:
move.l d0,d3
move.l d1,d4
move.b #0,d0 * 0 = black
move.l myraster,a1
move.l graphicsbase,a6
SYS SetAPen(a6)
move.l d3,d0
move.l d4,d1
lsr.w #6,d0
lsr.w #6,d1
and.l #$ffff,d0
and.l #$ffff,d1
SYS WritePixel(a6)
rts
*************************************************************
pset:
move.l d0,d3
move.l d1,d4
move.b #1,d0 * 1 = white
move.l graphicsbase,a6
move.l myraster,a1
SYS SetAPen(a6)
move.l d3,d0
move.l d4,d1
lsr.l #6,d0
lsr.l #6,d1
and.l #$ffff,d0
and.l #$ffff,d1
SYS WritePixel(a6)
rts
*************************************************************
point_maker:
jsr rando * x values
move.w d0,d2
and.w #x_and,d0
add.w #xlower,d0
move.w d0,xold_st(a3)
jsr rando * y values
and.w #y_and,d0
add.w #ylower,d0
cmp.w #y_rang,d0
bls rep_y
asr.w #1,d0
rep_y:
move.w d0,yold_st(a3)
and.b #3,d2 * side distance factor
add.b #1,d2
move.b d2,dx_st(a3)
rts
**********************************************************
* Random number generator with d0 returning the number (others saved)
randomize:
move.w #91,d0 * the seed
move.w d0,rndsav
move.b #91,d0
move.b d0,rndlow
rts
rando:
move.l a0,-(sp)
move.l d1,-(sp)
lea rndsav,a0
move.w #$4321,d0
mulu (a0),d0
add.l #1,d0
move.w d0,(a0)
move.b (a0),d1
eor.b d0,d1
move.b d1,rndlow
move.l (sp)+,d1
move.l (sp)+,a0
rts
************************************************************
* get message to see if user closed the window
getmsg:
move.l _AbsExecBase,a6
move.l newwindowptr,a0
move.l wd_UserPort(a0),a0
SYS GetMsg(a6)
rts
************************************************************
* reply to the current message
replymsg:
move.l d0,a1
move.l _AbsExecBase,a6
SYS ReplyMsg(a6)
rts
************************************************************
* Wait for user to close the window
waitforbutton:
move.l _AbsExecBase,a6
move.l newwindowptr,a0
move.l wd_UserPort(a0),a1
move.l #0,d3
move.b MP_SIGBIT(a1),d3
move.l #1,d0
asl.l d3,d0
SYS Wait(a6)
rts
*************************************************************
* Close a window
closeall:
move.l intuitionbase,a6
move.l newwindowptr,a0
SYS CloseWindow(a6)
* Close a screen
move.l intuitionbase,a6
move.l newscreenptr,a0
SYS CloseScreen(a6)
* Close the graphics library
move.l graphicsbase,a1
move.l _AbsExecBase,a6
SYS CloseLibrary(a6)
* Close the intuition library
move.l intuitionbase,a1
move.l _AbsExecBase,a6
SYS CloseLibrary(a6)
rts
*************************************************************
openerr:
moveq #-1,d1 * return code=bad
move.l d1,d0
bra exitprog
****************************************************************************
* Library definitions
theintuition dc.b 'intuition.library',0
cnop 0,2
thegraphics dc.b 'graphics.library',0
cnop 0,2
* Andrew's Title definitions
andrews_window dc.b '3D Stars V 1.0',0
cnop 0,2
andrews_screen dc.b 'Andrew',39,'s Screen',0
cnop 0,2
* Uninitialized variable definitions
Uninitdata section vars,bss
startbss
intuitionbase ds.l 1 * base addr. for intuit. calls
graphicsbase ds.l 1 * base addr. for graphics calls
myraster ds.l 1 * pointer to new screen raster
myview ds.l 1 * pointer to new screen viewport
newwindowptr ds.l 1 * pointer to new window
newscreenptr ds.l 1 * pointer to new screen
rndsav ds.w 2
rndlow ds.b 4
savesp ds.l 1
* star variables
speed ds.b 2
numb equ $40
lenth equ $10
pont ds.b numb*lenth
pontend ds.b 1
x_centre ds.w 1
y_centre ds.w 1
x_abs ds.w 1
y_abs ds.w 1
xnew_st equ 0
ynew_st equ 2
dx_st equ 4
dy_st equ 6
xold_st equ 8
yold_st equ $a
viaddr equ $c
vidata equ $e
x_and equ 254*$40
x_rang equ 318*64
zero equ 0
y_and equ 254*$40
y_rang equ 197*64
xlower equ 3*$40
ylower equ 11*$40
endbss
* Initialized variable defintions
initdata section vars,data
startdata
windowvars dc.w 0 * nw_LeftEdge
dc.w 0 * nw_TopEdge
dc.w 320 * nw_Width
dc.w 200 * nw_Height
dc.b 0 * nw_DetailPen
dc.b 1 * nw_BlockPen
dc.l IDCMP_FLAGS * nw_IDCMPFlags
dc.l ANDREWSGADGETS * nw_FLAGS
dc.l 0 * nw_FirstGadget
dc.l 0 * nw_CheckMark
dc.l andrews_window * nw_Title
dc.l 0 * nw_Screen
dc.l 0 * nw_BitMap
dc.w 0 * nw_Minwidth
dc.w 0 * nw_MinHeight
dc.w 320 * nw_MaxWidth
dc.w 200 * nw_MaxHeight
dc.w WBENCHSCREEN * nw_Type
screenvars dc.w 0 * ns_LeftEdge
dc.w 0 * ns_TopEdge
dc.w 320 * ns_Width
dc.w 200 * ns_Height
dc.w 3 * ns_Depth
dc.b 3 * ns_DetailPen
dc.b 1 * ns_BlockPen
dc.w 0 * ns_ViewModes
dc.w WBENCHSCREEN * ns_Type
dc.l 0 * ns_Font
dc.l andrews_screen * ns_DefaultTitle
dc.l 0 * ns_Gadgets
dc.l 0 * ns_CustomBitMap
enddata
end